import java.util.Arrays;

public class project {
    public int minIncrementForUnique(int[] nums) {
        int ret=0;
        Arrays.sort(nums);
        for(int i=1;i<nums.length;i++){
            if(nums[i-1]>=nums[i]){
                int prev=nums[i];
                nums[i]=nums[i-1]+1;
                ret+=nums[i]-prev;
            }
        }
        return ret;
    }














    public int numSteps(String s) {
        int len=s.length();
        int ret=0;
        boolean flag=false;
        for(int i=len-1;i>0;i--){
            char ch=s.charAt(i);
            if(ch=='0'&&!flag){
                ret++;
            }else if(ch=='0'&&flag||ch=='1'&&!flag){
                ret+=2;
                flag=true;
            }else{
                ret++;
                flag=true;
            }
        }
        if(flag){
            ret++;
        }
        return ret;
    }














    public int findKthNumber(int m, int n, int k) {
        int left=1;
        int right=m*n;
        while (left<right){
            int mid=left+(right-left)/2;
            if(count(m,n,mid)>=k){
                right=mid;
            }else{
                left=mid+1;
            }
        }
        return left;
    }

    private int count(int m, int n, int mid) {
        int ret=0;
        for(int i=1;i<=m;i++){
            ret+=Math.min(n,mid/i);
        }
        return ret;
    }
}
